/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: SmsListener
 * Author:   zhouheng
 * Date:     2019/3/30 10:53
 * Description: 短信监听器
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.onesquare.sms.listener;

import com.aliyuncs.exceptions.ClientException;
import com.onesquare.sms.config.SmsConfig;
import com.onesquare.sms.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈短信监听器〉
 *
 * @author zhouheng
 * @create 2019/3/30
 * @since 1.0.0
 */
@Component
//@RabbitListener(queues = "hello-sms",containerFactory = "simpleRabbitListenerContainerFactory")
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @Autowired
    private SmsConfig smsConfig;

    @RabbitListener(queues = "hello-sms", containerFactory="rabbitListenerContainerFactory")
    @RabbitHandler
    public void executeSms(Map<String, String> map){
        String mobile = map.get("mobile");
        String checkCode = map.get("checkCode");
        System.out.println("手机号："+map.get("mobile"));
        System.out.println("验证码："+map.get("checkCode"));

        try {
            smsUtil.sendSms(mobile,smsConfig.getTemplateCode(),smsConfig.getSignName(),"{\"code\":\""+checkCode+"\"}");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

//    @RabbitListener(queues = "hello-sms", containerFactory="rabbitListenerContainerFactory")
//    @RabbitHandler
//    public void sendSms(String msg){
//        System.out.println(msg);
//    }

}